#!/bin/bash
#
# start the Jenkins swarm client
#
# invoke with the following arguments:
# -executors ${EXECUTORS} -labels "${LABELS}" -disableClientsUniqueId
#
# it should be started using the jenkins.service file on Linux
# or via crontab on macos as follows:
# @reboot /Users/jenkins/swarm.sh -executors 1 -labels macos
#


cd $(dirname $0)
PATH=/usr/local/bin:$PATH

JENKINS_URL="http://jenkins.db.cs.cmu.edu:8080"
# note that the following username is immaterial - the password is what matters
USERNAME="worker"
# this is a github token generated by crd
PASSWORD="REDACTED"

# fetch the latest version from the server
curl -sO ${JENKINS_URL}/swarm/swarm-client.jar

# or else fall back to the prepopulated version
java -jar swarm-client.jar -mode exclusive -name "$(hostname)-${RANDOM}" -master "${JENKINS_URL}" -username ${USERNAME} -password ${PASSWORD} -fsroot /tmp -deleteExistingClients $@
